import base64

string = 'zhangsan'

def encode(string) :

    if isinstance(string,str) :
        string = string.encode('utf-8')
    elif isinstance(string,bytes) :
        string = string
    else:
        raise Exception('need bytes')
    _string = base64.encodebytes(string).decode('utf-8')
    _string = _string.replace('e','@').replace('m',"+")
    return _string

def decode(sting) :
    sting = sting.replace('@','e').replace('+','m')
    sting = sting.encode('utf-8')
    if not isinstance(sting,bytes):
        raise Exception('nend btyes')
    return base64.decodebytes(sting).decode('utf-8')


if __name__ == "__main__" :
    _string = encode(string)
    print(_string,type(_string))
    print(decode(_string))

